#!/bin/bash
# Assumes you're in a git repository
export SENTRY_AUTH_TOKEN=2ae725339707465c9b0b993acafa897dd7a82c253e244b88bc0f128d6630f1b0
export SENTRY_ORG=zwcfgl
VERSION=$(sentry-cli releases propose-version)

if [ "$1" = "production" ]
then
  ENV_FILE=".env.prod"
elif [ "$1" = "test" ]
then
  ENV_FILE=".env.test"
elif [ "$1" = "dev1" ]
then
  ENV_FILE=".env.dev"
fi

# 替换sentry配置版本号
mv $ENV_FILE "${ENV_FILE}.bak"
cat "${ENV_FILE}.bak" | while read line
do
   echo ${line/VUE_APP_SENTRY_RELEASE*/VUE_APP_SENTRY_RELEASE = \'$VERSION\'} >> $ENV_FILE
done
rm -f "${ENV_FILE}.bak"


if [ "$1" = "production" ]
then
# Create a release
sentry-cli --url https://sentry.tool.zwcfgl.com/ releases new -p zw_pc $VERSION

# Associate commits with the release
sentry-cli --url https://sentry.tool.zwcfgl.com/ releases set-commits --auto $VERSION

# Tell Sentry When You Deploy a Release
sentry-cli --url https://sentry.tool.zwcfgl.com/ releases deploys $VERSION new -e 'production'

fi
